﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zj.OpenAuth.Domain.Core;

namespace Zj.OpenAuth.Repository.Models.Mapping
{
    /// <summary>
    /// user fluent api maping
    /// </summary>
    public class UserMap
        : EntityTypeConfiguration<User>
    {

        public UserMap()
        {
            //table
            ToTable("User", "dbo");

            //keys
            HasKey(t => t.Id);

            //properties
            this.Property(t => t.Id)
                .HasColumnName("Id")
                .IsRequired();

            this.Property(t => t.Account)
                .HasColumnName("Account")
                .HasMaxLength(20)
                .IsRequired();

            this.Property(t => t.RealName)
                .HasColumnName("RealName")
                .HasMaxLength(20)
                .IsRequired();

            this.Property(t => t.Password)
                .HasColumnName("Password")
                .HasMaxLength(64)
                .IsRequired();

            this.Property(t => t.Code)
                .HasColumnName("Code")
                .HasMaxLength(36);

            this.Property(t => t.Phone)
                .HasColumnName("Phone")
                .HasMaxLength(20);

            this.Property(t => t.Mobile)
                .HasColumnName("Mobile")
                .HasMaxLength(20);

            this.Property(t => t.Email)
               .HasColumnName("Email")
               .HasMaxLength(100);

            this.Property(t => t.Address)
               .HasColumnName("Address")
               .HasMaxLength(50);

            this.Property(t => t.QQ)
                .HasColumnName("QQ");

            this.Property(t => t.WeChat)
                .HasColumnName("WeChat")
                .HasMaxLength(50);

            this.Property(t => t.Sex)
                .HasColumnName("Sex")
                .IsRequired();

            this.Property(t => t.Status)
                .HasColumnName("Status")
                .IsRequired();

            this.Property(t => t.Description)
              .HasColumnName("Description")
              .HasMaxLength(1000);

            this.Property(t => t.DepartmentId)
                .HasColumnName("DepartmentId")
                .IsOptional();

            this.Property(t => t.CreatorId)
                .HasColumnName("CreatorId")
                .IsOptional();

            this.Property(t => t.CreateTime)
                .HasColumnName("CreateTime")
                .IsRequired();

            this.Property(t => t.LastModifierId)
                .HasColumnName("LastModifierId")
                .IsOptional();

            this.Property(t => t.LastModifyTime)
                .HasColumnName("LastModifyTime")
                .IsOptional();
        }
    }
}
